package com.kkb.controller.ordermanager;

import com.github.pagehelper.PageInfo;
import com.kkb.bean.OrderTable;
import com.kkb.bean.User;
import com.kkb.service.ordermanager.OrderManagerService;
import com.kkb.vo.BaseResp;
import com.kkb.vo.ordermanager.req.SelectOrderReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderManagerController {

    @Autowired
    private OrderManagerService orderManagerService;

    @GetMapping("queryOrder")
    public BaseResp<Map<String,Object>> queryOrder(SelectOrderReq param, HttpServletRequest request, HttpServletResponse response){
        if (param.getPageNum()==null){
            param.setPageNum(1);
        }
        //TODO 这里从session取信息需要和user模块对接
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        param.setSellerId(user.getUserId());
        PageInfo<OrderTable> orderTablePageInfo = orderManagerService.selectOrder(param);
        Map<String, Object> map = new HashMap<>();
        map.put("orderTablePageInfo",orderTablePageInfo);
        map.put("param",param);
        return new BaseResp<>(map);
    }

}
